﻿angular.module('app.dataprepare', [])
    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider

        .when('/initaging', {
            templateUrl: 'app/dataprepare/dataprepare-list.tpl.html',
            controller: 'dataprepareListCtrl',
            resolve: {
                //首次加载第一页
                initAging: ['initagingProxy', function (initagingProxy) {
                    return initagingProxy.initagingPaging(1, 15, "");
                } ],
                bdHoldstatus: ['baseDataProxy', function (baseDataProxy) {
                    return baseDataProxy.SysTypeDetail("005");
                } ],
                lstRet: ['initagingProxy', function (initagingProxy) {
                    return initagingProxy.query({ para1: 1, para2: 2 });
                } ],
                lstSubmitDatasRet: ['periodProxy', function (periodProxy) {
                    return periodProxy.query({ reportType: "Aging" });
                } ],
                oneYearRet: ['periodProxy', function (periodProxy) {
                    return periodProxy.query({ reportType: "OneYearSales" });
                } ],
                strCurrentPer: ['periodProxy', function (periodProxy) {
                    return periodProxy.queryObject({ cur: '1' });
                } ],
                lstHisAreaRet: ['periodProxy', function (periodProxy) {
                    return periodProxy.hisAreaPeroidPaging(1, 15);
                }]

            }
        });
    } ])

//*****************************************body***************************s
    .controller('dataprepareListCtrl',
    ['$scope', 'modalService', 'initAging', 'initagingProxy', 'baseDataProxy', 'siteProxy',
    '$http', 'bdHoldstatus', 'agingDownloadProxy', 'FileUploader', 'APPSETTING',
    'lstRet', 'collectionProxy', 'lstSubmitDatasRet', 'periodProxy', 'lstHisAreaRet',
    'strCurrentPer', 'oneYearRet', 
        function ($scope, modalService, initAging, initagingProxy, baseDataProxy, siteProxy,
        $http, bdHoldstatus, agingDownloadProxy, FileUploader, APPSETTING,
        lstRet, collectionProxy, lstSubmitDatasRet, periodProxy, lstHisAreaRet,
        strCurrentPer, oneYearRet) {

            //*************upload **********************s
            var uploader = $scope.uploader = new FileUploader({
                url: APPSETTING['serverUrl'] + '/api/Collection'
            });

            // FILTERS

            uploader.filters.push({
                name: 'customFilter',
                fn: function (item /*{File|FileLikeObject}*/, options) {
                    if (item.name.toString().toUpperCase().split(".")[1] != "TXT"
                        && item.name.toString().toUpperCase().split(".")[1] != "XLSX"
                        && item.name.toString().toUpperCase().split(".")[1] != "ZIP") {
                        alert("File format is not correct !");
                    }
                    return this.queue.length < 100;
                }
            });

            //added by alex
            $scope.dropdownvalue = "Aging Report";
            $scope.updcolor = "#FFCC33";
            $scope.submitcolor = "#FFCC33";
            $scope.dlhcolor = "#FFCC33";
            $scope.agingTotalNum = 0;
            $scope.oneYearTotalNum = 0;
            $scope.hisTotalNum = 0;

            $scope.legalEntityList = lstRet;
            document.getElementById("currentPeriodTime").innerHTML = strCurrentPer;

            $scope.submitDatasList = lstSubmitDatasRet;
            $scope.oneYearSalesValueList = oneYearRet;

            var message = "";
            var indexNo = 1;
            var totalCount = 0;
            // CALLBACKS
            uploader.onSuccessItem = function (fileItem, response, status, headers) {

                if (indexNo == 1 && uploader.queue[0] !== "") {
                    totalCount = totalCount + 1;
                }
                if (indexNo == 1 && uploader.queue[1] !== "") {
                    totalCount = totalCount + 1;
                }
                if (indexNo == 1 && uploader.queue[2] !== "") {
                    totalCount = totalCount + 1;
                }

                message = message + response;

                if (indexNo == totalCount) {
                    document.getElementById("overlay-container").style.display = "none";
                    alert(message);
                    console.info('onSuccessItem', fileItem, message, status, headers);

                    $scope.search();
                    periodProxy.query({ reportType: "Aging" }, function (submitList) {
                        $scope.submitDatasList = submitList;
                    });

                    $scope.clearInfo("updAccountFile");
                    $scope.clearInfo("updInvoiceFile");
                    $scope.clearInfo("updOneYearSalesFile");
                } else {
                    indexNo++;
                }
            };
            uploader.onErrorItem = function (fileItem, response, status, headers) {
                document.getElementById("overlay-container").style.display = "none";
                alert(response);
                console.info('onErrorItem', fileItem, response, status, headers);

                $scope.search();
                periodProxy.query({ reportType: "Aging" }, function (submitList) {
                    $scope.submitDatasList = submitList;
                });

                $scope.clearInfo("updAccountFile");
                $scope.clearInfo("updInvoiceFile");
                $scope.clearInfo("updOneYearSalesFile");
            };

            console.info('uploader', uploader);

            $scope.updateLevel = function () {
                messgeInfo = "";

                if (uploader.queue.length <= 0) {
                    alert("Please select the file you need to upload!");
                    return;
                } else if (uploader.queue[0] == "" && uploader.queue[1] == "" && uploader.queue[2] == "") {
                    alert("Please select the file you need to upload!");
                    return;
                } else if (uploader.queue[0] !== "" && uploader.queue[1] == "" && uploader.queue[2] == "") {
                    alert("Account and Invoice files must be selected!");
                    return;
                } else if (uploader.queue[0] == "" && uploader.queue[1] !== "" && uploader.queue[2] == "") {
                    alert("Account and Invoice files must be selected!");
                    return;
                } else if (uploader.queue[0] !== "" && uploader.queue[1] == "" && uploader.queue[2] !== "") {
                    alert("Please only choice One-Year Sales File!");
                    return;
                } else if (uploader.queue[0] == "" && uploader.queue[1] !== "" && uploader.queue[2] !== "") {
                    alert("Please only choice One-Year Sales File!");
                    return;
                }

                if (uploader.queue[0] !== "" && uploader.queue[0]._file.name.toString().toUpperCase().split(".")[1] != "TXT"
                    && uploader.queue[0]._file.name.toString().toUpperCase().split(".")[1] != "ZIP") {
                    alert("Account File format is not correct, \nPlease select the '.txt' file !");
                    return;
                }

                if (uploader.queue[1] !== "" && uploader.queue[1]._file.name.toString().toUpperCase().split(".")[1] != "TXT"
                    && uploader.queue[1]._file.name.toString().toUpperCase().split(".")[1] != "ZIP") {
                    alert("Invoice File format is not correct, \nPlease select the '.txt' file !");
                    return;
                }

                if (uploader.queue[2] !== "" && uploader.queue[2]._file.name.toString().toUpperCase().split(".")[1] != "XLSX") {
                    alert("One-Year Sales File format is not correct, \nPlease select the '.xlsx' file !");
                    return;
                }

                document.getElementById("overlay-container").style.display = "block";

                for (var i = 0; i < 3; i++) {
                    uploader.queue[i].url = APPSETTING['serverUrl'] + '/api/Collection' + '?levelFlag=' + i;
                }

                indexNo = 1;
                message = "";
                totalCount = 0;

                uploader.uploadAll();
            };

            $scope.selectedLevel = 15;          //下拉单页容量初始化(Confirm Area)
            $scope.selectedOneYearLevel = 15;   //下拉单页容量初始化(One Year Sales)
            $scope.selectedHisAreaLevel = 15;   //下拉单页容量初始化(His Area)
            $scope.itemsperpage = 15;           //对应页(Confirm Area)
            $scope.oneyearitemsperpage = 15;    //对应页(One Year Sales)
            $scope.hisareaitemsperpage = 15;    //对应页(His Area)
            $scope.currentPage = 1;
            $scope.oneyearcurrentPage = 1;
            $scope.hisareacurrentPage = 1;
            $scope.maxSize = 10;
            $scope.oneyearmaxSize = 10;
            $scope.hisareamaxSize = 10;
            var filstr = "";


            //单页容量下拉列表定义
            $scope.levelList = [
                            { "id": 15, "levelName": '15' },
                            { "id": 500, "levelName": '500' },
                            { "id": 1000, "levelName": '1000' },
                            { "id": 2000, "levelName": '2000' },
                            { "id": 5000, "levelName": '5000' }
            ];

            //footer items calculate
            $scope.agingCalculate = function (count) {
                if (count == 0) {
                    $scope.agingFromItem = 0;
                } else {
                    $scope.agingFromItem = ($scope.currentPage - 1) * $scope.itemsperpage + 1;
                }
                $scope.agingToItem = ($scope.currentPage - 1) * $scope.itemsperpage + count;
            }
            $scope.oneYearCalculate = function (count) {
                if (count == 0) {
                    $scope.oneYearFromItem = 0;
                } else {
                    $scope.oneYearFromItem = ($scope.oneyearcurrentPage - 1) * $scope.oneyearitemsperpage + 1;
                }
                $scope.oneYearToItem = ($scope.oneyearcurrentPage - 1) * $scope.oneyearitemsperpage + count;
            }
            $scope.hisCalculate = function (count) {
                if (count == 0) {
                    $scope.hisFromItem = 0;
                } else {
                    $scope.hisFromItem = ($scope.hisareacurrentPage - 1) * $scope.hisareaitemsperpage + 1;
                }
                $scope.hisToItem = ($scope.hisareacurrentPage - 1) * $scope.hisareaitemsperpage + count;
            }

            //加载nggrid数据绑定
            $scope.legalEntityCount = {
                data: 'legalEntityList',
                infiniteScrollUp: true,
                infiniteScrollDown: true,
                columnDefs: [
                    { field: 'legalEntity', displayName: 'Legal Entity', width: '130' },
                    { field: 'accTimes', displayName: 'Aging Report', width: '130' },
                    { field: 'oneYearTimes', displayName: 'One-Year Sales', width: '130' },
                    { field: 'reportTime', displayName: 'Report Date', width: '150' }
                ],
                onRegisterApi: function (gridApi) {
                    //set gridApi on scope
                    $scope.gridApi = gridApi;
                }
            };

            $scope.clearInfo = function (items) {
                if (uploader.queue.length > 0) {
                    if (items == "updAccountFile") {
                        uploader.queue[0] = "";
                    } else if (items == "updInvoiceFile") {
                        uploader.queue[1] = "";
                    } else {
                        uploader.queue[2] = "";
                    }
                }
                messgeInfo = "";
                document.getElementById(items).value = "";
            };

            //*************upload **********************e

            $scope.isShow = true;
            $scope.isOneYearShow = false;

            $scope.showAging = function () {
                $scope.dropdownvalue = "Aging Report";
                $scope.isShow = true;
                $scope.isOneYearShow = false;
            };

            $scope.showOneYear = function () {
                $scope.dropdownvalue = "One-Year Sales";
                $scope.isShow = false;
                $scope.isOneYearShow = true;

                initagingProxy.initagingPagingOneYearList(1, 15, function (list) {
                    $scope.oneYearList = list[0].results;
                    $scope.oneyeartotalItems = list[0].count;
                    $scope.oneYearTotalNum = list[0].count;
                    $scope.oneYearCalculate(list[0].results.length);
                });

                periodProxy.query({ reportType: "OneYearSales" }, function (list) {
                    $scope.oneYearSalesValueList = list;
                    if ($scope.oneYearSalesValueList.length > 0) {
                        document.getElementById("oneYearSalesValue").innerHTML = $scope.oneYearSalesValueList[0].oneYearTimes;
                        document.getElementById("reportDateValue").innerHTML = $scope.oneYearSalesValueList[0].reportTime;
                    } else {
                        document.getElementById("oneYearSalesValue").innerHTML = "";
                        document.getElementById("reportDateValue").innerHTML = "";
                    }
                });

            };

            //加载nggrid数据绑定
            $scope.oneYear = {
                data: 'oneYearList',
                columnDefs: [
                    { field: 'billGroupCode', displayName: 'Factory Group Code' },
                    { field: 'billGroupName', displayName: 'Group Name' },
                    { field: 'oneYearSales', displayName: 'One Year Sales', cellFilter: 'number:2', type: 'number' }
                ],
                onRegisterApi: function (gridApi) {
                    //set gridApi on scope
                    $scope.gridApi = gridApi;
                }
            };

            //Legal Entity DropDownList数据绑定
            siteProxy.Site("", function (legallist) {
                $scope.legallist = legallist;
            });
            //Status Entity DropDownList数据绑定
            $scope.bdHoldstatus = bdHoldstatus;

            ////One Year Sales 初期化数据赋值(ui-grid)
            //if (lstOneYearRet) {
            //    $scope.oneYearList = lstOneYearRet[0].results; //首次当前页数据
            //    $scope.oneyeartotalItems = lstOneYearRet[0].count; //查询结果初始化
            //}

            //Confirm Area 初期化数据赋值(ui-grid)
            if (initAging) {
                $scope.list = initAging[0].results; //首次当前页数据
                $scope.totalItems = initAging[0].count; //查询结果初始化
                $scope.agingTotalNum = initAging[0].count;
                $scope.agingCalculate(initAging[0].results.length);
            }

            //His Area 初期化数据赋值(ui-grid)
            if (lstHisAreaRet) {
                $scope.hisAreaList = lstHisAreaRet[0].results;
                $scope.hisareatotalItems = lstHisAreaRet[0].count;
                $scope.hisTotalNum = lstHisAreaRet[0].count;
                $scope.hisCalculate(lstHisAreaRet[0].results.length);
            }

            //nggrid数据绑定
            $scope.griddatas = {
                multiSelect: true,
                enableFullRowSelection: true,
                // enableRowSelection: true,
                // enableSelectAll: true,
                enableSorting: true,
                data: 'list',
                columnDefs: [
                    { field: 'legalEntity', displayName: 'Legal Entity', width: '100' },
                    { name: 'cc', displayName: 'Customer Code', width: '100',
                        cellTemplate: '<div class="ui-grid-cell-contents ngCellText" ng-class="col.colIndex()">{{row.entity.customerNum}} &nbsp; <img ng-click="resetSearch();" ng-show="row.entity.cusExFlg == 0" src="~/../Content/images/259.png"></div>'
                    },
                    { field: 'customerName', displayName: 'Customer Name', width: '255' },
                    { field: 'billGroupName', displayName: 'Factory Group Name', width: '255' },
                //                    { field: 'customerClass', displayName: 'Customer Class', width: '70' },
                //                    { field: 'riskScore', displayName: 'Risk Score', width: '80' },
                    { field: 'totalAmt', displayName: 'Total A/R Balance', width: '90', cellFilter: 'number:2', type: 'number' },
                //                    { field: 'due90Amt', displayName: 'Over 90 days', width: '90', cellFilter: 'number' },
                    { field: 'creditLimit', displayName: 'Credit Limit', width: '90', cellFilter: 'number:2', type: 'number' },
                    { field: 'isHoldFlg', displayName: 'Account Status', width: '90',
                        cellTemplate: '<div hello="{valueMember: \'isHoldFlg\', basedata: \'grid.appScope.bdHoldstatus\'}"></div>'
                    },
                    { field: 'collector', displayName: 'Operator', width: '120'
                        //cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()">{{row.entity.collector}} <img ng-click="grid.appScope.showPop(row.entity);"  src="~/../Content/images/331.png"></div>'
                    }
                ]
            };

            $scope.search = function () {
                //组合过滤条件
                var filterStr = '';
                if ($scope.custCode) {
                    if (filterStr != "") {
                        filterStr += "and (contains(CustomerNum,'" + $scope.custCode + "'))";
                    } else {
                        filterStr += "&$filter=(contains(CustomerNum,'" + $scope.custCode + "'))";
                    }
                }
                if ($scope.custName) {
                    if (filterStr != "") {
                        filterStr += "and (contains(CustomerName,'" + $scope.custName + "'))"
                    } else {
                        filterStr += "&$filter=(contains(CustomerName,'" + $scope.custName + "'))";
                    }

                }
                if ($scope.class) {
                    if (filterStr != "") {
                        filterStr += "and (CustomerClass eq '" + $scope.class + "')";
                    } else {
                        filterStr += "&$filter=(CustomerClass eq '" + $scope.class + "')";
                    }
                }
                if ($scope.status) {
                    if (filterStr != "") {
                        filterStr += "and (IsHoldFlg eq '" + $scope.status + "')";
                    } else {
                        filterStr += "&$filter=(IsHoldFlg eq '" + $scope.status + "')";
                    }
                }
                if ($scope.legal) {
                    if (filterStr != "") {
                        filterStr += "and (LegalEntity eq '" + $scope.legal + "')";
                    } else {
                        filterStr += "&$filter=(LegalEntity eq '" + $scope.legal + "')";
                    }
                }
                if (document.getElementById("ckbMasterData").checked) {
                    if (filterStr != "") {
                        filterStr += "and (CusExFlg eq '0')";
                    } else {
                        filterStr += "&$filter=(CusExFlg eq '0')";
                    }
                }
                //                if (document.getElementById("ckbAccountData").checked) {
                //                    if (filterStr != "") {
                //                        filterStr += "and (AmtMappingFlg eq '2')";
                //                    } else {
                //                        filterStr += "&$filter=(AmtMappingFlg eq '2')";
                //                    }
                //                }
                if (document.getElementById("ckbInvoiceData").checked) {
                    if (filterStr != "") {
                        filterStr += "and (AmtMappingFlg eq '2')";
                    } else {
                        filterStr += "&$filter=(AmtMappingFlg eq '2')";
                    }
                }
                if (document.getElementById("ckbTotalAmountNotEqual").checked) {
                    if (filterStr != "") {
                        filterStr += "and (AmtMappingFlg eq '1')";
                    } else {
                        filterStr += "&$filter=(AmtMappingFlg eq '1')";
                    }
                }

                filstr = filterStr;

                $scope.currentPage = 1;
                initagingProxy.initagingPaging($scope.currentPage, $scope.itemsperpage, filterStr, function (list) {
                    if (list != null) {
                        $scope.totalItems = list[0].count;
                        $scope.list = list[0].results;
                        $scope.agingTotalNum = list[0].count;
                        $scope.agingCalculate(list[0].results.length);
                    }
                })

            };

            //单页容量变化
            $scope.pagesizechange = function (selectedLevelId) {
                var index = $scope.currentPage;
                initagingProxy.initagingPaging(index, selectedLevelId, filstr, function (list) {
                    $scope.itemsperpage = selectedLevelId;
                    $scope.list = list[0].results;
                    $scope.totalItems = list[0].count;
                    $scope.agingTotalNum = list[0].count;
                    $scope.agingCalculate(list[0].results.length);
                });
            };

            //翻页
            $scope.pageChanged = function () {
                var index = $scope.currentPage;
                initagingProxy.initagingPaging(index, $scope.itemsperpage, filstr, function (list) {
                    $scope.list = list[0].results;
                    $scope.totalItems = list[0].count;
                    $scope.agingTotalNum = list[0].count;
                    $scope.agingCalculate(list[0].results.length);
                }, function (error) {
                    alert(error);
                });
            };

            //单页容量变化(One Year Sales)
            $scope.oneyearpagesizechange = function (selectedOneYearLevelId) {
                var oyindex = $scope.oneyearcurrentPage;
                initagingProxy.initagingPagingOneYearList($scope.oneyearcurrentPage, selectedOneYearLevelId, function (list) {
                    $scope.oneyearitemsperpage = selectedOneYearLevelId;
                    $scope.oneYearList = list[0].results;
                    $scope.oneyeartotalItems = list[0].count;
                    $scope.totalNum = list[0].count;
                    $scope.calculate(list[0].results.length);
                });
            };

            //翻页(One Year Sales)
            $scope.oneyearpageChanged = function (oneyearcurrentPage) {
                initagingProxy.initagingPagingOneYearList(oneyearcurrentPage, $scope.oneyearitemsperpage, function (list) {
                    $scope.oneYearList = list[0].results;
                    $scope.oneyeartotalItems = list[0].count;
                    $scope.oneYearTotalNum = list[0].count;
                    $scope.oneYearCalculate(list[0].results.length);
                }, function (error) {
                    alert(error);
                });
            };

            //单页容量变化(His Area)
            $scope.hisareapagesizechange = function (selectedHisAreaLevelId) {
                var index = $scope.hisareacurrentPage;
                periodProxy.hisAreaPeroidPaging(index, selectedHisAreaLevelId, function (list) {
                    $scope.hisareaitemsperpage = selectedHisAreaLevelId;
                    $scope.hisAreaList = list[0].results;
                    $scope.hisareatotalItems = list[0].count;
                    $scope.hisTotalNum = list[0].count;
                    $scope.hisCalculate(list[0].results.length);
                });
            };

            //翻页(His Area)
            $scope.hisareapageChanged = function () {
                var index = $scope.hisareacurrentPage;
                periodProxy.hisAreaPeroidPaging(index, $scope.hisareaitemsperpage, function (list) {
                    $scope.hisAreaList = list[0].results;
                    $scope.hisareatotalItems = list[0].count;
                    $scope.hisTotalNum = list[0].count;
                    $scope.hisCalculate(list[0].results.length);
                }, function (error) {
                    alert(error);
                });
            };

            //保存单行数据
            $scope.Save = function (entity) {
                entity.$update(function () {
                    alert("Save Success");
                }, function () {
                    alert("Save Error");
                });

            }

            //submit
            $scope.submit = function (items) {
                if (items == "Aging") {
                    initagingProxy.query({ custIds: '1' }, function () {
                        alert("Success!");
                        $scope.search();
                        initagingProxy.query({ para1: 1, para2: 2 }, function (legalList) {
                            $scope.legalEntityList = legalList;
                        });

                        periodProxy.hisAreaPeroidPaging(1, 15, function (hisList) {
                            $scope.hisAreaList = hisList[0].results;
                            $scope.hisareatotalItems = hisList[0].count;
                            $scope.hisTotalNum = hisList[0].count;
                            $scope.hisCalculate(hisList[0].results.length);
                        });

                    }, function (error) {
                        alert(error);
                    })
                } else {
                    initagingProxy.query({ custIds: '2' }, function () {
                        alert("Success!");

                        initagingProxy.initagingPagingOneYearList(1, 15, function (list) {
                            $scope.oneYearList = list[0].results;
                            $scope.oneyeartotalItems = list[0].count;
                            $scope.oneYearTotalNum = list[0].count;
                            $scope.oneYearCalculate(list[0].results.length);
                        });

                        periodProxy.query({ reportType: "OneYearSales" }, function (list) {
                            $scope.oneYearSalesValueList = list;
                            if ($scope.oneYearSalesValueList.length > 0) {
                                document.getElementById("oneYearSalesValue").innerHTML = $scope.oneYearSalesValueList[0].oneYearTimes;
                                document.getElementById("reportDateValue").innerHTML = $scope.oneYearSalesValueList[0].reportTime;
                            } else {
                                document.getElementById("oneYearSalesValue").innerHTML = "";
                                document.getElementById("reportDateValue").innerHTML = "";
                            }
                        });

                        initagingProxy.query({ para1: 1, para2: 2 }, function (legalList) {
                            $scope.legalEntityList = legalList;
                        });

                        periodProxy.hisAreaPeroidPaging(1, 15, function (hisList) {
                            $scope.hisAreaList = hisList[0].results;
                            $scope.hisareatotalItems = hisList[0].count;
                            $scope.hisTotalNum = hisList[0].count;
                            $scope.hisCalculate(hisList[0].results.length);
                        });

                    }, function (error) {
                        alert(error);
                    })
                }
            };


            //加载nggrid数据绑定
            $scope.submitDatasCount = {
                data: 'submitDatasList',
                columnDefs: [
                    { field: 'legalEntity', displayName: 'Legal Entity', width: '130' },
                    { field: 'accTimes', displayName: 'Account Level', width: '131', cellFilter: 'number:2', type: 'number' },
                    { field: 'invTimes', displayName: 'Invoice Level', width: '131', cellFilter: 'number:2', type: 'number' },
                    { field: 'reportTime', displayName: 'Report Date', width: '150' }
                ],
                onRegisterApi: function (gridApi) {
                    //set gridApi on scope
                    $scope.gridApi = gridApi;
                }
            };

            //nggrid数据绑定
            $scope.hisArea = {
                multiSelect: true,
                enableFullRowSelection: true,
                enableSorting: true,
                data: 'hisAreaList',
                columnDefs: [
                    { field: 'period', displayName: 'Period', width: '275' },
                    { name: 'fileType', displayName: 'Report Type', width: '220' },
                    { field: 'operator', displayName: 'Operator', width: '220' },
                    { field: 'operatorDate', displayName: 'Time', width: '220', cellFilter: 'date:\'yyyy-MM-dd HH:mm:ss\'' },
                    {
                        field: 'downLoadFlg', displayName: 'Consolidated File', width: '163',
                        cellTemplate: '<div class="ngCellText" ng-class="col.colIndex()"  style="text-align:center">' +
                                      '<a class="glyphicon glyphicon-download-alt" ng-click="grid.appScope.download(row.entity.downLoadFullName)" ng-show="row.entity.downLoadShowFlg == 1" title="DownLoad"></a>' +
                                      //'<button ng-click="grid.appScope.download(row.entity.downLoadFullName)" ng-show="row.entity.downLoadShowFlg == 1">' +
                                      //'DownLoad</button>　&nbsp;&nbsp;&nbsp;&nbsp;　' +
                        //                                      '<img id="imgRefresh" ng-click="grid.appScope.resetSearch();" ng-show="row.entity.periodFlg == 1" src="~/../Content/images/refreshBg.png"></div>'
                        //                                      '<button class="glyphicon glyphicon-refresh" style="height:24px" ng-click="grid.appScope.resetSearch();" ng-show="row.entity.periodFlg == 1"></button>' + 
                                      '</div>'
                    }
                ]
            };

            //download
            $scope.download = function (fullNamePath) {
                if (fullNamePath == null || fullNamePath == "") {
                    alert("There is no need to download the file!");
                } else {
                    window.location = fullNamePath;
                }
            };

            //清空过滤条件
            $scope.resetSearch = function () {
                //document.getElementById("imgRefresh").src = "~/../Content/images/refresh.png";
                agingDownloadProxy.refreshDownloadFile(function (res) {
                    alert("Refresh Success!");
                    periodProxy.hisAreaPeroidPaging(1, 15, function (hisList) {
                        $scope.hisAreaList = hisList[0].results;
                        $scope.hisareatotalItems = hisList[0].count;
                        $scope.hisTotalNum = hisList[0].count;
                        $scope.hisCalculate(hisList[0].results.length);
                    });
                }, function (error) {
                    alert(error);
                    //document.getElementById("imgRefresh").src = "~/../Content/images/refreshBg.png";
                });
            }, function (error) {
                alert(error);
            };

            //area show
            $scope.show = function (type) {
                $("#").removeClass('ng-hide');
                if (type == "upload") {
                    $("#updAreaShow").hide();
                    $("#updAreaHide").show();
                    $("#tblUploadArea").show();
                    $scope.updcolor = "#FFCC33";
                } else if (type == "submit") {
                    $("#updSubmitComfirmShow").hide();
                    $("#updSubmitComfirmHide").show();
                    $("#tblSubmitComfirm").show();
                    $scope.submitcolor = "#FFCC33";
                } else if (type == "download") {
                    $("#downloadHisShow").hide();
                    $("#downloadHisHide").show();
                    $("#tblDownloadArea").show();
                    $scope.dlhcolor = "#FFCC33";
                }
            }
            //area hide
            $scope.hide = function (type) {
                $("#").addClass('ng-hide');
                if (type == "upload") {
                    $("#updAreaShow").show();
                    $("#updAreaHide").hide();
                    $("#tblUploadArea").hide();
                    $scope.updcolor = "#0072c6";
                } else if (type == "submit") {
                    $("#updSubmitComfirmShow").show();
                    $("#updSubmitComfirmHide").hide();
                    $("#tblSubmitComfirm").hide();
                    $scope.submitcolor = "#0072c6";
                } else if (type == "download") {
                    $("#downloadHisShow").show();
                    $("#downloadHisHide").hide();
                    $("#tblDownloadArea").hide();
                    $scope.dlhcolor = "#0072c6";
                }
            }

        } ])